<?php
namespace App\Http\Controllers\Home;
use App\Http\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use App\Models\PartnerMeetingModels\MeetingOrder;
class HomeAjaxController extends ApiBaseController {
  public function __construct(Request $request) {
    parent::__construct($request);
  }
  
  public function yearAmount(){
    $oOrder = new \App\Models\OrderModels\Order();
    $year = $this->params['year'];
    $start_time = strtotime(date($year.'-01-01'));
    $end_time = strtotime(date($year.'-12-31 23:59:59'));
    $total_amount = $oOrder->getSumAmount($start_time, $end_time);
    $oMeetingOrder = new \App\Models\MeetingModels\Order();
    $meeting_amount = $oMeetingOrder->getSumPayPrice($start_time,$end_time);
    $this->data['total_amount'] = round($total_amount,2) + round($meeting_amount,2);
    $list = [];
    //大会
    $this->data['meeting_amount'] = round($meeting_amount,2);
    if($meeting_amount > 0){
      $list[] = [
        'value' => round($meeting_amount,2),
        'color' => '#FFD700',
        'highlight' => '#FFD700',
        'label' => '大会'
      ];
    }
    //邦币
    $bangbi_amount = $oOrder->getSumAmount($start_time, $end_time,1);
    $this->data['bangbi_amount'] = round($bangbi_amount,2);
    if($bangbi_amount > 0){
      $list[] = [
        'value' => round($bangbi_amount,2),
        'color' => '#f56954',
        'highlight' => '#f56954',
        'label' => '邦币'
      ];
    }
    //会员
    $vip_amount = $oOrder->getSumAmount($start_time, $end_time,4);
    $this->data['vip_amount'] = round($vip_amount,2);
    if($vip_amount > 0){
      $list[] = [
        'value' => round($vip_amount,2),
        'color' => '#00a65a',
        'highlight' => '#00a65a',
        'label' => '会员'
      ];
    }
    //课程
    $course_amount = $oOrder->getSumAmount($start_time, $end_time,2);
    $this->data['course_amount'] = round($course_amount,2);
    if($course_amount > 0){
      $list[] = [
        'value' => round($course_amount,2),
        'color' => '#f39c12',
        'highlight' => '#f39c12',
        'label' => '课程'
      ];
    }
    //直播间
    $live_course_amount = $oOrder->getSumAmount($start_time, $end_time,5);
    $this->data['live_course_amount'] = round($live_course_amount,2);
    if($live_course_amount > 0){
      $list[] = [
        'value' => round($live_course_amount,2),
        'color' => '#00c0ef',
        'highlight' => '#00c0ef',
        'label' => '直播'
      ];
    }
    //专栏
    $column_amount = $oOrder->getSumAmount($start_time, $end_time,8);
    $this->data['column_amount'] = round($column_amount,2);
    if($column_amount > 0){
      $list[] = [
        'value' => round($column_amount,2),
        'color' => '#3c8dbc',
        'highlight' => '#3c8dbc',
        'label' => '专栏'
      ];
    }
    //线上特训营
    $training_amount = $oOrder->getSumAmount($start_time, $end_time,7);
    $this->data['training_amount'] = round($training_amount,2);
    if($training_amount > 0){
      $list[] = [
        'value' => round($training_amount,2),
        'color' => '#FF00FF',
        'highlight' => '#FF00FF',
        'label' => '线上特训营'
      ];
    }
    //2020中国教育培训行业报告
    $oActivityOrder = new MeetingOrder();
    $report_2020 = $oActivityOrder->getSumAmount($start_time,$end_time,[10038]);
    $this->data['report_2020'] = round($report_2020,2);
    if($report_2020 > 0){
      $list[] = [
        'value' => round($report_2020,2),
        'color' => '#000',
        'highlight' => '#000',
        'label' => '2020中国教育培训行业报告'
      ];
    }
    $this->data['list'] = $list;
    $this->boot();
  }
  
  /**
   * 首页校长邦产品收益表
   */
  public function productAmount(){
    $oOrder = new \App\Models\OrderModels\Order();
    $year = $this->params['year'];
    $start_date = date($year.'-01-01');
    $end_date = date($year.'-12-31 23:59:59');
    $start_time = strtotime($start_date);
    $end_time = strtotime($end_date);
    //在线课程收入（1､会员 2､直播 3､单课 4､专栏 5、邦币）
    $online_course_amount = $oOrder->getSumAmount($start_time, $end_time);
    //线下课程收入（1､精英校长特训营 2､卓越校长商学院）
    $oActivityOrder = new MeetingOrder();
    $offline_course_jy_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10034,10033,10032,10031,10030,10024,10021,10017]);
    $offline_course_zy_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10022,10025,10026,10029]);
    $offline_course_amount = $offline_course_jy_amount + $offline_course_zy_amount;
    //出版物（1､行业报告 2､教培机构一点通）
    $publication_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10038,10036,10028]);
    //大会活动（1､双T大会 2､沙龙活动）
    $oMeetingOrder = new \App\Models\MeetingV2Models\Order();
    $meeting_tt_amount = $oMeetingOrder->getSumPayPrice($start_date,$end_date);
    $meeting_sl_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10020,10019,10016,10013,10010,10040]);
    $meeting_amount = $meeting_tt_amount + $meeting_sl_amount;
    //合计
    $total_amount = $online_course_amount+$offline_course_amount+$publication_amount+$meeting_amount;
    $res = [];
    //在线课程
    $res['product_amount_1_1'] = $online_course_amount;
    $res['product_amount_1_3'] = $res['product_amount_1_2'] = $total_amount == 0 ? '0%' : round($online_course_amount*100/$total_amount,2).'%';
    //线下课程
    $res['product_amount_2_1'] = $offline_course_amount;
    $res['product_amount_2_3'] = $res['product_amount_2_2'] = $total_amount == 0 ? '0%' : round($offline_course_amount*100/$total_amount,2).'%';
    //出版物
    $res['product_amount_3_1'] = $publication_amount;
    $res['product_amount_3_3'] = $res['product_amount_3_2'] = $total_amount == 0 ? '0%' : round($publication_amount*100/$total_amount,2).'%';
    //大会活动
    $res['product_amount_4_1'] = $meeting_amount;
    $res['product_amount_4_3'] = $res['product_amount_4_2'] = $total_amount == 0 ? '0%' : round($meeting_amount*100/$total_amount,2).'%';
    //合计
    $res['product_amount_5_1'] = $total_amount;
    $this->data = $res;
    $this->boot();
  }
  
  /**
   * 首页校长邦大学表
   */
  public function xzbUniversity(){
    $oOrder = new \App\Models\OrderModels\Order();
    $res = [];
    $res['xzb_university_1_1'] = $oOrder->getCountOrders(true);   //今日订单数
    $res['xzb_university_1_2'] = $oOrder->getCountOrders();       //累计订单数
    $oUser = new \App\Models\UserModels\User();
    $res['xzb_university_2_1'] = $oUser->getCountUsers(true);     //累计会员数
    $res['xzb_university_2_2'] = $oUser->getCountUsers();         //累计用户数
    $oDriedFood = new \App\Models\CourseModels\DriedFood();
    $df_count = $oDriedFood->getCountCourses();                   //课程数量
    $oLiveCourse = new \App\Models\CourseModels\LiveCourse();
    $lc_count = $oLiveCourse->getCountLiveCourses();              //直播回放数量
    $res['xzb_university_3_1'] = $df_count + $lc_count;           //课程数 = 课程数量 + 直播回放数量
    $res['xzb_university_3_2'] = $oDriedFood->getCountCourses(3); //专业校长体系课课程数
    $oVideo = new \App\Models\CourseModels\Video();
    $courseAudios = $oVideo->getCountAudios_();                   //音视频数
    $res['xzb_university_4_1'] = $courseAudios + $lc_count;       //音视频数 + 直播回放数量
    $res['xzb_university_4_2'] = $oVideo->getZYCountAudios();     //专业校长体系课音视频数
    $course_durations = $oVideo->getTotalDuration_();             //课程总时长
    $live_course_durations = $oLiveCourse->getTotalDuration();    //直播总时长
    $res['xzb_university_5_1'] = intval(($course_durations + $live_course_durations)/60);       //总时长
    $zyDurations = $oVideo->getZYTotalDuration();
    $res['xzb_university_5_2'] = intval($zyDurations/60);         //专业校长体系课音视频时长
    $this->data = $res;
    $this->boot();
  }
  
  /**
   * 在线课程（1､会员 2､直播 3､单课 4､专栏 5、邦币）
   */
  public function onlineCourse(){
    $oOrder = new \App\Models\OrderModels\Order();
    $year = $this->params['year'];
    $start_time = strtotime(date($year.'-01-01'));
    $end_time = strtotime(date($year.'-12-31 23:59:59'));
    $total_amount = $oOrder->getSumAmount($start_time, $end_time);
    $this->data['o_c_1'] = round($total_amount,2);
    $list = [];
    //会员
    $vip_amount = $oOrder->getSumAmount($start_time, $end_time,4);
    $this->data['o_c_2'] = round($vip_amount,2);
    if($vip_amount > 0){
      $list[] = [
        'value' => round($vip_amount,2),
        'color' => '#00a65a',
        'highlight' => '#00a65a',
        'label' => '会员'
      ];
    }
    //直播间
    $live_course_amount = $oOrder->getSumAmount($start_time, $end_time,5);
    $this->data['o_c_3'] = round($live_course_amount,2);
    if($live_course_amount > 0){
      $list[] = [
        'value' => round($live_course_amount,2),
        'color' => '#00c0ef',
        'highlight' => '#00c0ef',
        'label' => '直播间'
      ];
    }
    //课程
    $course_amount = $oOrder->getSumAmount($start_time, $end_time,2);
    $this->data['o_c_4'] = round($course_amount,2);
    if($course_amount > 0){
      $list[] = [
        'value' => round($course_amount,2),
        'color' => '#f39c12',
        'highlight' => '#f39c12',
        'label' => '课程'
      ];
    }
    //线上特训营
    $training_amount = $oOrder->getSumAmount($start_time, $end_time,7);
    $this->data['o_c_5'] = round($training_amount,2);
    if($training_amount > 0){
      $list[] = [
        'value' => round($training_amount,2),
        'color' => '#FF00FF',
        'highlight' => '#FF00FF',
        'label' => '线上特训营'
      ];
    }
    //专栏
    $column_amount = $oOrder->getSumAmount($start_time, $end_time,8);
    $this->data['o_c_6'] = round($column_amount,2);
    if($column_amount > 0){
      $list[] = [
        'value' => round($column_amount,2),
        'color' => '#3c8dbc',
        'highlight' => '#3c8dbc',
        'label' => '专栏'
      ];
    }
    //邦币
    $bangbi_amount = $oOrder->getSumAmount($start_time, $end_time,1);
    $this->data['o_c_7'] = round($bangbi_amount,2);
    if($bangbi_amount > 0){
      $list[] = [
        'value' => round($bangbi_amount,2),
        'color' => '#f56954',
        'highlight' => '#f56954',
        'label' => '邦币'
      ];
    }
    $this->data['list'] = $list;
    $this->boot();
  }
  
  /**
   * 线下课程（1､精英校长特训营 2､卓越校长商学院）
   */
  public function offlineCourse(){
    $year = $this->params['year'];
    $start_date = date($year.'-01-01');
    $end_date = date($year.'-12-31 23:59:59');
    $oActivityOrder = new MeetingOrder();
    $list = [];
    //精英校长特训营
    $offline_course_jy_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10034,10033,10032,10031,10030,10024,10021,10017]);
    $this->data['of_c_2'] = round($offline_course_jy_amount,2);
    if($offline_course_jy_amount > 0){
      $list[] = [
        'value' => round($offline_course_jy_amount,2),
        'color' => '#00a65a',
        'highlight' => '#00a65a',
        'label' => '精英校长特训营'
      ];
    }
    //卓越校长商学院
    $offline_course_zy_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10022,10025,10026,10029]);
    $this->data['of_c_3'] = round($offline_course_zy_amount,2);
    if($offline_course_zy_amount > 0){
      $list[] = [
        'value' => round($offline_course_zy_amount,2),
        'color' => '#f39c12',
        'highlight' => '#f39c12',
        'label' => '卓越校长商学院'
      ];
    }
    $this->data['of_c_1'] = round($offline_course_jy_amount+$offline_course_zy_amount,2);
    $this->data['list'] = $list;
    $this->boot();
  }
  
  /**
   * 出版物（1､行业报告 2､教培机构一点通）
   */
  public function publication(){
    $year = $this->params['year'];
    $start_date = date($year.'-01-01');
    $end_date = date($year.'-12-31 23:59:59');
    $oActivityOrder = new MeetingOrder();
    $list = [];
    //行业报告
    $report_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10038]);
    $this->data['p_c_2'] = round($report_amount,2);
    if($report_amount > 0){
      $list[] = [
        'value' => round($report_amount,2),
        'color' => '#00a65a',
        'highlight' => '#00a65a',
        'label' => '行业报告'
      ];
    }
    //教培机构一点通
    $ydt_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10036,10028]);
    $this->data['p_c_3'] = round($ydt_amount,2);
    if($ydt_amount > 0){
      $list[] = [
        'value' => round($ydt_amount,2),
        'color' => '#f39c12',
        'highlight' => '#f39c12',
        'label' => '教培机构一点通'
      ];
    }
    $this->data['p_c_1'] = round($report_amount+$ydt_amount,2);
    $this->data['list'] = $list;
    $this->boot();
  }
  
  /**
   * 大会活动（1､双T大会 2､沙龙活动）
   */
  public function meetingActivity(){
    $year = $this->params['year'];
    $start_date = date($year.'-01-01');
    $end_date = date($year.'-12-31 23:59:59');
    $start_time = strtotime(date($year.'-01-01'));
    $end_time = strtotime(date($year.'-12-31 23:59:59'));
    $oActivityOrder = new MeetingOrder();
    $list = [];
    //双T大会
    $oMeetingOrder = new \App\Models\MeetingV2Models\Order();
    $meeting_tt_amount = $oMeetingOrder->getSumPayPrice($start_date,$end_date);
    $this->data['m_c_2'] = round($meeting_tt_amount,2);
    if($meeting_tt_amount > 0){
      $list[] = [
        'value' => round($meeting_tt_amount,2),
        'color' => '#00a65a',
        'highlight' => '#00a65a',
        'label' => '双T大会'
      ];
    }
    //沙龙活动
    $meeting_sl_amount = $oActivityOrder->getSumAmount($start_date,$end_date,[10020,10019,10016,10013,10010,10040]);
    $this->data['m_c_3'] = round($meeting_sl_amount,2);
    if($meeting_sl_amount > 0){
      $list[] = [
        'value' => round($meeting_sl_amount,2),
        'color' => '#f39c12',
        'highlight' => '#f39c12',
        'label' => '沙龙活动'
      ];
    }
    $this->data['m_c_1'] = round($meeting_tt_amount+$meeting_sl_amount,2);
    $this->data['list'] = $list;
    $this->boot();
  }
}